Capturing screen through C# is just like pressing Print Screen button on keyboard.
Example
//adding Imaging name space
using System.Drawing.Imaging;
privatevoid timer1_Tick(object sender, EventArgs e)
{
string filename;
string dir;
try
{
dir = "C:\\screen" + DateTime.Today.Day.ToString();
filename = dir + "\\screen" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".jpg";
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
//Set the bitmap object to the size of the screen
Bitmap screenShot = newBitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Take the screenshot from the upper left corner to the right bottom corner
Graphics screenGraphics = Graphics.FromImage(screenShot);
screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Save the screenshot
screenShot.Save(filename, ImageFormat.Jpeg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
privatevoid Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
}
Anonymous User
18-Mar-2019Thank You for the guidance.
Samuel Fernandes
26-Jul-2017Thanks for sharing informative post.